package
{
	import events.SlideEvent;
	
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * 控制栏组件 
	 * @author PC-100
	 * 
	 */	
	public class ControlBar extends Sprite
	{

		/**
		 * 上一张按钮 
		 */		
		private var backButton:BackButton;
		/**
		 * 下一张按钮 
		 */
		private var forwardButton:ForwardButton;
		/**
		 * 播放按钮 
		 */
		private var playButton:PlayButton;
		/**
		 * 暂停按钮
		 */
		private var pauseButton:PauseButton;
		
		public function ControlBar()
		{
			super();
			
			// 背景
			var g:Graphics = this.graphics;
			g.beginFill(0x0,0.6);
			g.drawRect(0,0,500,33);
			g.endFill();
			// 初始化所有按钮
			backButton = new BackButton();
			forwardButton = new ForwardButton();
			playButton = new PlayButton();
			pauseButton = new PauseButton();
			
			this.addChild( backButton );
			this.addChild( forwardButton );
			this.addChild( playButton );
			this.addChild( pauseButton );
			
			backButton.x = 10;
			forwardButton.x = 100;
			playButton.x = 40;
			pauseButton.x = 40;
			
			backButton.y = 5;
			forwardButton.y = 5;
			playButton.y = 5;
			pauseButton.y = 5;
			// 设置鼠标手型
			backButton.buttonMode = backButton.useHandCursor = true;
			forwardButton.buttonMode = forwardButton.useHandCursor = true;
			playButton.buttonMode = playButton.useHandCursor = true;
			pauseButton.buttonMode = pauseButton.useHandCursor = true;
			// 监听click事件
			backButton.addEventListener(MouseEvent.CLICK, onBack);
			forwardButton.addEventListener(MouseEvent.CLICK, onForward);
			playButton.addEventListener(MouseEvent.CLICK, onPlay);
			pauseButton.addEventListener(MouseEvent.CLICK, onPause);
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		protected function onPause(event:MouseEvent):void
		{
			this.dispatchEvent( new SlideEvent(SlideEvent.SLIDE, SlideEvent.PAUSE) );
			pauseButton.visible = false;
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		protected function onPlay(event:MouseEvent):void
		{
			this.dispatchEvent( new SlideEvent(SlideEvent.SLIDE, SlideEvent.PLAY));
			pauseButton.visible = true;
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		protected function onForward(event:MouseEvent):void
		{
			this.dispatchEvent( new SlideEvent(SlideEvent.SLIDE, SlideEvent.FORWARD));
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		protected function onBack(event:MouseEvent):void
		{
			this.dispatchEvent( new SlideEvent(SlideEvent.SLIDE, SlideEvent.BACK));
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
}